<%--
  Created by IntelliJ IDEA.
  User: dhd
  Date: 2024/6/4
  Time: 9:05
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%--<link rel="stylesheet" href="${pageContext.request.contextPath}/bootstrap/css/bootstrap.min.css">--%>
<script src="${pageContext.request.contextPath}/js/jquery-1.11.3.js"></script>
<head>
    <title>新增员工</title>
    <style>
        .col-form-label{
            background-color: white;
            height: 30px;
            text-align: center;
            line-height: 30px;
        }
        .col-sm-10{
            color: #7abaff;
        }
    </style>
</head>
<body>
<div class="container-fluid">
    <div class="row">
        <form>
            <%--工号的输入框--%>
            <div class="form-group row" id="stuIdRow">
                <label for="employeeNo" class="col-sm-2 col-form-label">工号</label>
                <div class="col-sm-10">
                    <input type="text" class="form-control" id="employeeNo" name="employeeNo">
                </div>
            </div>
            <%--            &lt;%&ndash;密码的输入框&ndash;%&gt;--%>
            <%--            <div class="form-group row">--%>
            <%--                <label for="password" class="col-sm-2 col-form-label">密码</label>--%>
            <%--                <div class="col-sm-10">--%>
            <%--                    <input type="text" class="form-control" id="password" placeholder="请输入密码">--%>
            <%--                </div>--%>
            <%--            </div>--%>
            <%--姓名的输入框--%>
            <div class="form-group row">
                <label for="stuName" class="col-sm-2 col-form-label">姓名</label>
                <div class="col-sm-10">
                    <input type="text" class="form-control" id="stuName" placeholder="请输入密码">
                </div>
            </div>
            <%--头像--%>
            <div class="form-group row">
                <label for="image" class="col-sm-2 col-form-label">头像</label>
                <div class="col-sm-10">
                    <input type="file" class="form-control" id="image" placeholder="请选择头像：">
                </div>
            </div>
            <%--性别--%>
            <div class="form-group row">
                <label class="col-sm-2 col-form-label">性别</label>
                <div class="col-sm-10">
                    <input type="radio" name="sex" value="男" checked>男
                    <input type="radio" name="sex" value="女">女
                </div>
            </div>
            <%--生日--%>
            <div class="form-group row">
                <label for="birthday" class="col-sm-2 col-form-label">生日</label>
                <div class="col-sm-10">
                    <input type="date" class="form-control" id="birthday" placeholder="请选择生日：">
                </div>
            </div>
            <%--部门--%>
            <div class="form-group row">
                <label for="depart" class="col-sm-2 col-form-label">部门</label>
                <div class="col-sm-10">
                    <select id="depart" class="form-control ">
                        <option selected value="-1">全部</option>
                    </select>
                </div>
            </div>
            <%--职位--%>
            <div class="form-group row">
                <label for="position" class="col-sm-2 col-form-label">职位</label>
                <div class="col-sm-10">
                    <select id="position" class="form-control ">
                        <option selected value="-1">全部</option>
                    </select>
                </div>
            </div>
            </fieldset>
            <%--手机号--%>
            <div class="form-group row">
                <label for="phone" class="col-sm-2 col-form-label">手机号</label>
                <div class="col-sm-10">
                    <input type="text" class="form-control" id="phone" placeholder="请输入手机号">
                </div>
            </div>
            <%--邮箱--%>
            <div class="form-group row">
                <label for="email" class="col-sm-2 col-form-label">邮箱</label>
                <div class="col-sm-10">
                    <input type="text" class="form-control" id="email">
                </div>
            </div>
            <input type="button" value="提交" id="tijiao">
        </form>
    </div>
</div>

</body>
</html>
<script>
    $(function () {
        //获取部门全部
        let departUrl = "${pageContext.request.contextPath}/staffmanage.action"
        $.ajax({
            url: departUrl,
            type: 'post',
            data: {opr: "list1"},
            dataType: 'json',
            success: departList,
            error: function () {
                alert("查询失败！")
            }
        })

        //回调函数，加载数据
        function departList(data) {
            console.log(data);
            data.forEach(dd => {
                $('#depart').append(`<option value="` + dd.id + `">` + dd.deptName + `</option>`)
            })
            //获取职位全部
            let positionUrl = "${pageContext.request.contextPath}/staffmanage.action"
            $.ajax({
                url: positionUrl,
                type: 'get',
                data: {opr: "list2"},
                dataType: 'json',
                success: positionList,
                error: function () {
                    alert("查询失败！")
                }
            })
        }

        //回调函数，加载数据
        function positionList(data) {
            console.log(data);
            data.forEach(dd => {
                $('#position').append(`<option value="` + dd.id + `">` + dd.positionName + `</option>`)
            })
        }
    })


    //提交按钮
    $('#tijiao').click(function () {
        let opr = "add";
        let employeeNo = $('#employeeNo').val()
        let stuName = $('#stuName').val()
        let sex = $("input[name='sex']:checked").val();
        let birthday = $('#birthday').val()
        let depart = $('#depart').val()
        let position = $('#position').val()
        let phone = $('#phone').val()
        let email = $('#email').val()
        let params = {opr, employeeNo, stuName, sex, birthday, depart, position, phone, email}
        $.ajax({
            url: "${pageContext.request.contextPath}/staffmanage.action",
            type: 'post',
            data: params,
            dataType: 'json',
            success: function (data) {
                console.log(data);
                if (data.code == 'ok') {
                    location.reload();
                }
            },
            error: function () {
                alert("新增失败!");
            }
        })
    })

</script>
